package com.t9101DR.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.t9101DR.bean.RoomAddress;
import com.t9101DR.service.RoomAddressService;
import com.t9101DR.service.impl.RoomAddressServiceImpl;

/**
 * Servlet implementation class DrUserServlet
 */
@WebServlet("/DrUserServlet")
public class DrUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DrUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		//action是请求的操作类别
		String action=request.getParameter("action");
		RoomAddress stu=new RoomAddress();
		
		RoomAddressService newsService=new RoomAddressServiceImpl(); 
		if(action==null || "list".equals(action)) {
			//从请求中拿到数据
				String newsTitle = request.getParameter("name");
				if(newsTitle!=""&&newsTitle!=null) {
					
						stu.setAddressId(Integer.parseInt(newsTitle));
					
				}
				
			//根据请求中的数据调用业务逻辑层的方法
	
			List<RoomAddress> list=newsService.list(stu);
			
			//页面的跳转和数据的设置
		request.setAttribute("newsList", list);
		request.setAttribute("listSize", list.size());
		request.setAttribute("newsTitle", newsTitle);
		request.getRequestDispatcher("tgls/agent/agent_list.jsp").forward(request, response);
		
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
